//
//  CQMianController.swift
//  weibo
//
//  Created by chengqiang on 16/7/18.
//  Copyright © 2016年 chengqiangBiaodashi. All rights reserved.
//

import UIKit

class CQMianController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar = CQTabBar()
        mainTabBar.composeBack={()->Void in
            if CQUserViewModel.shareduserAccountViewModel.userLogin{
                let composeVC = CQComposeController()
                self.presentViewController(UINavigationController(rootViewController:composeVC), animated: true, completion: nil)
            }else{
                let oatuVc = CQQauthViewController()
                self.presentViewController(UINavigationController(rootViewController:oatuVc), animated: true, completion: nil)
            }
        }
        self.setValue(mainTabBar, forKey: "tabBar")
        addControllers()
     
        
    }
    
    ///加载子控制器
    func addControllers(){
//        let homVC = CQHomeController()
//        homVC.title="首页"
//        homVC.tabBarItem.title="首页"
//        homVC.tabBarItem.image=UIImage(named: "tabbar_home")
//        self.addChildViewController(UINavigationController(rootViewController: homVC))
        
        
//        let messagevc = CQMessageController()
//        messagevc.title="信息"
//        messagevc.tabBarItem.title="信息"
//        messagevc.tabBarItem.image=UIImage(named: "tabbar_message_center")
//        self.addChildViewController(UINavigationController(rootViewController: messagevc))
//        
//        
//        let discorvervc = CQDiscorverController()
//        discorvervc.title="发现"
//        discorvervc.tabBarItem.title="发现"
//        discorvervc.tabBarItem.image=UIImage(named: "tabbar_discover")
//        self.addChildViewController(UINavigationController(rootViewController: discorvervc))
//        
//        let profileVC = CQProfileController()
//        profileVC.title="我"
//        profileVC.tabBarItem.title="我"
//        profileVC.tabBarItem.image=UIImage(named: "tabbar_profile")
//        
//        self.addChildViewController(UINavigationController(rootViewController: profileVC))
        
        addController(CQHomeController(), title: "首页", imageName: "tabbar_home")
        addController(CQMessageController(), title: "信息", imageName: "tabbar_message_center")
        addController(CQDiscorverController(), title: "发现", imageName: "tabbar_discover")
        addController(CQProfileController(), title: "我", imageName: "tabbar_profile")

    }
    
    ///提取方法创建子控制器
    func addController(controller:UIViewController,title:String,imageName:String) {
         controller.title=title
        
         ///设置选中字体颜色
         controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState:UIControlState.Selected)
       
         controller.tabBarItem.image=UIImage(named: imageName)
         let selectImage = imageName+"_selected"
   
         ///设置选中图片为原始状态  不自动渲染
         controller.tabBarItem.selectedImage=UIImage(named: selectImage)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
         self.addChildViewController(UINavigationController(rootViewController: controller))
    }

 
}
